package com.dyna.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dyna.core.LambdaQueryWrapperX;
import com.dyna.domain.resp.PageResult;
import com.dyna.foundation.domain.entity.SysDictData;
import com.dyna.foundation.domain.req.SysDictDataPageReq;
import org.apache.ibatis.annotations.Mapper;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;

@Mapper
public interface SysDictDataMapper extends BaseMapperX<SysDictData> {

    default SysDictData selectByDictTypeAndValue(String dictType, String value) {
        return selectOne(SysDictData::getDictType, dictType, SysDictData::getDictValue, value);
    }

    default SysDictData selectByDictTypeAndLabel(String dictType, String label) {
        return selectOne(SysDictData::getDictType, dictType, SysDictData::getDictLabel, label);
    }

    default List<SysDictData> selectByDictTypeAndValues(String dictType, Collection<String> values) {
        return selectList(new LambdaQueryWrapper<SysDictData>().eq(SysDictData::getDictType, dictType)
                .in(SysDictData::getDictValue, values));
    }

    default long selectCountByDictType(String dictType) {
        return selectCount(SysDictData::getDictType, dictType);
    }

    default PageResult<SysDictData> selectPage(SysDictDataPageReq reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<SysDictData>()
                .likeIfPresent(SysDictData::getDictLabel, reqVO.getLabel())
                .eqIfPresent(SysDictData::getDictType, reqVO.getDictType())
                .eqIfPresent(SysDictData::getStatus, reqVO.getStatus())
                .orderByDesc(Arrays.asList(SysDictData::getDictType, SysDictData::getDictSort)));
    }

    default List<SysDictData> selectListByStatusAndDictType(Integer status, String dictType) {
        return selectList(new LambdaQueryWrapperX<SysDictData>()
                .eqIfPresent(SysDictData::getStatus, status)
                .eqIfPresent(SysDictData::getDictType, dictType));
    }

}